﻿using System;
using Eisk.BusinessEntities;
using Eisk.BusinessLogicLayer;

namespace Eisk.Web
{
    public partial class add_employee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ButtonSalary_Click(object sender, EventArgs e)
        {
            try
            {
                Employee newEmployee = null;

                newEmployee = new Employee();

                newEmployee.Name = TextBoxName.Text;
                newEmployee.Address = TextBoxAddress.Text;
                newEmployee.ContactNumber = TextBoxContactNumber.Text;
                newEmployee.Zip = TextBoxZip.Text;

                if (!string.IsNullOrEmpty(TextBoxSalary.Text))
                {
                    newEmployee.Salary = Convert.ToDouble(TextBoxSalary.Text.Trim());
                }

                new EmployeeBLL().CreateNewEmployee(newEmployee);
            }
            catch (Exception ex)
            {
                LiteralStatus.Text = "An internal Error occured!";
            }
        }
        protected void ButtonSaveSupplier_Click(object sender, EventArgs e)
        {
            try
            {
                string name;
                string address;
                string phone;
                string email;
                string zip;
                UIDataCollection(out name, out address, out phone, out email, out zip);

                Supplier newSupplier = null;
                SupplierBLL aSupplyBll = new SupplierBLL();

                if (!string.IsNullOrEmpty(Request.QueryString["supplierId"]))
                {
                    string supplierID = Request.QueryString["supplierId"];
                    int supplierId = Convert.ToInt16(supplierID);

                    newSupplier = aSupplyBll.GetSupplierBySupplierId(supplierId);
                }

                if (newSupplier != null)
                {
                    CollectSupplier(name, address, phone, email, zip, newSupplier);

                    aSupplyBll.UpdateSupplier(newSupplier);
                }
                else
                {
                    newSupplier = new Supplier();

                    if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(email))
                    {
                        CollectSupplier(name, address, phone, email, zip, newSupplier);

                        aSupplyBll.CreateNewSupplier(newSupplier);
                    }
                }

                Response.Redirect("view-suppliers.aspx");
            }
            catch (Exception ex)
            {
                LiteralStatus.Text = "An internal Error occured!";
            }
        }

        private void UIDataCollection(out string name, out string address, out string phone, out string email, out string zip)
        {
            throw new NotImplementedException();
        }

        private void CollectSupplier(string name, string address, string phone, string email, string zip, Supplier newSupplier)
        {
            throw new NotImplementedException();
        }
    }
}